package com.wx.mp.controller;

import com.wx.mp.dao.TCarOpDao;
import com.wx.mp.dao.TCarSubscribeDao;
import com.wx.mp.domain.TCarOp;
import com.wx.mp.request.subscribe.query.QuerySubscribeInfosReq;
import com.wx.mp.request.subscribe.query.QuerySubscribeInfosRes;
import com.wx.mp.utils.BizResult;
import com.wx.mp.utils.BizResultVO;
import com.wx.mp.utils.PageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Api(value = "登陆", description = "登陆")
@RestController
@RequestMapping("/wx/admin")
public class LoginAdminController extends BizController{

    private static final Logger logger = LoggerFactory.getLogger(LoginAdminController.class);

    @Autowired
    private TCarOpDao tCarOpDao;
    /**
     * 登陆.<br/>
     * @return
     */
    @ApiOperation("登陆")
    @PostMapping("/login")
    public BizResultVO<Boolean> login(@RequestParam String userName,@RequestParam String pwd){
        final TCarOp carOp = tCarOpDao.login(userName, pwd);
        //将信息放入session中
        setOpInfoToSession(carOp);
        return new BizResultVO<Boolean>().setData(true);
    }

    /**
     * 修改密码.<br/>
     * @return
     */
    @ApiOperation("修改密码")
    @PostMapping("/modifyPwd")
    public BizResultVO<Boolean> modifyPwd(@RequestParam String pwd){
        TCarOp carOp = getOpInfoBySession();
        tCarOpDao.modifyPwd(carOp.getId(),pwd);
        //更新session
        carOp.setLoginPassword(pwd);
        setOpInfoToSession(carOp);
        return new BizResultVO<Boolean>().setData(true);
    }
}
